package com.bluefoxyu.controller;

import com.bluefoxyu.domain.dto.EnrollmentDTO;
import com.bluefoxyu.domain.result.Result;
import com.bluefoxyu.domain.dto.StudentDTO;
import com.bluefoxyu.domain.entity.Student;
import com.bluefoxyu.domain.vo.CourseVO;
import com.bluefoxyu.domain.vo.StudentCourseVO;
import com.bluefoxyu.domain.vo.StudentVO;
import com.bluefoxyu.mapper.StudentMapper;
import com.bluefoxyu.service.ICourseService;
import com.bluefoxyu.service.IEnrollmentService;
import com.bluefoxyu.service.IStudentService;
import com.bluefoxyu.utils.BaseContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 学生信息表 前端控制器
 * </p>
 *
 * @author bluefoxyu
 * @since 2024-06-16
 */
@RestController
@RequestMapping("/student")
@RequiredArgsConstructor
@Tag(name ="学生页面学生接口")
public class StudentController {

    private final IStudentService studentService;
    private final StudentMapper studentMapper;
    private final IEnrollmentService enrollmentService;
    private final ICourseService courseService;

    @Operation(summary = "学生登录")
    @PostMapping("/login")
    public Result<StudentVO> login(@RequestBody StudentDTO studentDTO){
        return Result.success(studentService.login(studentDTO));
    }

    /**
     * 根据查询学生信息
     * @return 学生信息
     */
    @Operation(summary = "查询学生信息")
    @GetMapping("/getByStudent")
    public Result<Student> getByStudent(){
        return Result.success(studentMapper.selectById(BaseContext.getCurrentId()));
    }

    @Operation(summary = "学生修改信息")
    @PutMapping("/update")
    public Result<String> updateStudentInfo(@RequestBody Student student){
        studentMapper.updateById(student);
        return Result.success("学生信息修改成功");
    }

    //学生可以利用学号和密码登录系统，登陆系统后，可以进行选课

    /**
     * 学生选课
     * @param enrollmentDTO 选课信息
     */
    @Operation(summary = "学生选课")
    @PutMapping("/AddCourse")
    public Result<String> AddCourse(@RequestBody EnrollmentDTO enrollmentDTO){
        enrollmentService.AddCourse(enrollmentDTO,BaseContext.getCurrentId());
        return Result.success("选课成功");
    }

    /**
     * 查询学生的总学分
     * @return 总学分
     */
    @Operation(summary = "查询学生的总学分")
    @GetMapping("selectStudentCredit")
    public Result<BigDecimal> selectStudentCredit(){
        return Result.success(studentService.selectStudentCredit(BaseContext.getCurrentId()));
    }

    @Operation(summary = "学生查看自己的选课情况")
    @GetMapping("/selectStudentCourse")
    public Result<List<StudentCourseVO>> selectCourseCreditAndScore(){
        return Result.success(studentService.selectStudentCourse(BaseContext.getCurrentId()));
    }

    @Operation(summary = "查询所有教师所授课程")
    @GetMapping("/getAllCourses")
    public Result<List<CourseVO>> getAllCourses() {
        return Result.success(courseService.getAllCourses());
    }

}
